package com.cskaoyan.config;

import com.cskaoyan.service.UserService;
import org.springframework.aop.framework.ProxyFactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

/**
 * @author stone
 * @date 2022/08/03 10:22
 */
@Configuration
@ComponentScan("com.cskaoyan")
public class SpringConfiguration {

    //方法名作为组件id
    @Bean
    public ProxyFactoryBean userServiceProxy(UserService userService) {
        ProxyFactoryBean proxyFactoryBean = new ProxyFactoryBean();
        // 提供两个值生成代理对象的实例
        proxyFactoryBean.setTarget(userService); //委托类
        // 容器中有通知组件，通知组件的id → countTimeAdvice
        // 提供的是字符串的id，能否在ProxyFactoryBean中获得该id对应的组件呢？
        // 能，但是要有容器对象
        proxyFactoryBean.setInterceptorNames("countTimeAdvice"); //通知组件的id

        return proxyFactoryBean;
    }

}
